package org.zanpu.metadataserver.core.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.zanpu.metadataserver.api.util.TableEnum;
import org.zanpu.metadataserver.core.dbmanager.InsertVo;
import org.zanpu.metadataserver.core.metadata.service.MetadataService;
import org.zanpu.metadataserver.core.util.ValuesUtil;

import javax.annotation.Resource;
import java.util.Map;

/**
 * Created by MD on 2016/10/31.
 */
@Controller
@RequestMapping("/metadataNew")
public class MetadataNewController extends ControllerUtilities {
    @Resource
    private MetadataService metadataService;
    /**
     * 新增
     *
     * @param jsonStr
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/insert/{tableName}", method = RequestMethod.POST, consumes = "application/text;charset=UTF-8")
    public int insertSource(@RequestBody String jsonStr,@PathVariable("tableName") String tableName) {
        return metadataService.insert(InsertVo.build(tableName,ValuesUtil.insertValues(jsonStrToMap(jsonStr))));
    }
}
